<%+header%>
<%
    local jsonc = require "luci.jsonc"
%>
<script>
    (function(){
        var vue_prefix="<%=prefix%>";
        var myurl = window.location.pathname;
        window.addEventListener('popstate', function(){
            if (myurl != window.location.pathname 
              && window.location.pathname != vue_prefix 
              && ! window.location.pathname.startsWith(vue_prefix+'/')) {
                window.location.href = window.location.pathname;
            }
        });
        window.vue_base = vue_prefix + '/';
        // window.istore_api_base = "https://istore.istoreos.com";
        // window.istore_icon_base = "https://istore.linkease.com.cdn.koolcenter.com";
        window.vue_lang_data = '/luci-static/istore/i18n/<%=lang%>.json?v=<%=id.version%>';
        window.vue_lang = '<%=lang%>';
        window.token = "<%=token%>";
        window.device_id = {arch:"<%=id.arch%>",uid:"<%=id.uid%>",version:"<%=id.version%>"};
        window.istore_features = <%=jsonc.stringify(features)%>.filter(f => f !== '_lua_force_array_');
        window.istore_config = <%=jsonc.stringify(user_config or {})%>;
    })();
</script>
<h2 name="content"><%:iStore%> 
    <a onclick="void(0)" href="https://github.com/linkease/istore/issues/22" target="_blank" style="text-decoration: none;">
        v<%=id.version%>
    </a>
</h2>
<link rel="stylesheet" href="/luci-static/istore/style.css?v=<%=id.version%>">
<div id="app">
</div>
<%+tasks/embed%>

<script>
    (function() {
        let beforeunloadRegistered = false;
        taskd.show_mask_on_stopped = true;
        window.istore_log = function(flush_menu_onclose, onExit) {
            if (flush_menu_onclose && !beforeunloadRegistered) {
                beforeunloadRegistered = true;
                window.addEventListener("beforeunload", function(event) {
                    try { window.L.ui.menu.flushCache() } catch (e) { }
                    return true;
                });
            }
            taskd.show_log("istore", true, onExit);
        };
    })();
<%
local taskd = require "luci.model.tasks"
local status = taskd.status("istore")
if status.running or status.exit_code ~= 404 then
-%>
    window.istore_log(true);
<%
end
%>
</script>

<script type="module" crossorigin src="/luci-static/istore/index.js?v=<%=id.version%>"></script>
<%+footer%>